package com.woniuxy.meal.controller.consumer;


import com.woniuxy.meal.entity.DietOrder;
import com.woniuxy.meal.service.DietOrderService;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(consumerGroup = "orders_pay",topic = "orders_payCheck")
public class PayCheckConsumer implements RocketMQListener<String> {

    @Autowired
    private DietOrderService dietOrderService;

    @Override
    public void onMessage(String num) {

        String result = dietOrderService.payOrderCheck(num);
        DietOrder orderInfo = dietOrderService.getById(num);
        if(result.equals("TRADE_SUCCESS")){
            dietOrderService.payCallback(orderInfo);
        }

        System.out.println(result);
    }
}
